package com.yeung.exam;

import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.Scanner;

/*
3
3
1 1 1
100 50 25
100 50 25
100 50 25
 */
public class Main {
static int max=0;
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int areas = sc.nextInt();
        int worker = sc.nextInt();
        int[] enable = new int[areas];
        for (int i = 0; i < areas; i++) {
            enable[i] = sc.nextInt();
        }
        //
        int[][] loveGraph = new int[worker][areas];
        for (int i = 0; i < loveGraph.length; i++) {
            for (int j = 0; j < areas; j++) {
                loveGraph[i][j] = sc.nextInt();
            }
        }
        //遍历每一列
        int result = getInfluence(loveGraph, 0, areas, enable);
        System.out.println(result);

    }

    public static int getInfluence(int[][] graph, int colIndex, int areas, int[] enable) {
        int result = 0;
        for (int i = colIndex; i < areas; i++) {
            for (int k = 1; k <= enable[i]; k++) {
                int sum = getMaxCloumnSum(graph, i, enable[k]);
                int tmp = getInfluence(graph, colIndex + 1, areas, enable);
//                if()
            }

        }
        return result;
    }

    public static int getMaxCloumnSum(int[][] data, int col, int pre) {
        List<Integer> colItems = new ArrayList<>();
        for (int i = 0; i < data.length; i++) {
            colItems.add(data[i][col]);
        }
        //获取前N的和
        Collections.sort(colItems);
        Collections.reverse(colItems);
        int sum = 0;
        for (int i = 0; i < pre; i++) {
            sum += colItems.get(i);
        }
        return sum;
    }
}